package com.filter.control.controller;

import com.filter.control.common.HttpProxyClient;
import com.filter.control.common.Result;
import com.filter.control.po.ContainerQuotaUpdatePO;
import com.filter.control.service.FilterServiceImpl;
import com.filter.control.vo.ExperimentVO;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 教学拦截器
 * @author
 */
@RestController
@RequestMapping(value = {"tes/experiment/training/**",
        "tes/experiment/course/**",
        "tes/image-allocation/training/**",
        "tes/image-allocation/course/**"} )
public class TrainingFilterController {

    @Value("${proxyStr}")
    private String proxyStr;

    @Autowired
    private HttpProxyClient httpProxyClient;

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String enterExperiment(HttpServletRequest request) {

        // 执行请求被代理系统
        System.out.println("被代理地址:" + proxyStr + request.getRequestURI());
        String str = httpProxyClient.sendMessagesNew(request, proxyStr + request.getRequestURI());
        String replace = str.replace("运行容器数已达到设置最大数，无法创建更多实验环境",
                "运行容器数已达到授权最大数，无法创建更多实验环境。请联系系统管理员");
        System.out.println("结果输出:" + replace);
        return replace;
    }
}
